package io.gitee.kotle.demo

import android.view.View
import android.widget.TextView
import androidx.viewbinding.ViewBinding
import io.gitee.kotle.android.adapter.RecyclerViewHolder
import io.gitee.kotle.android.utils.dp
import io.gitee.kotle.android.utils.onClick
import io.gitee.kotle.android.utils.setViewRadius
import io.gitee.kotle.demo.databinding.HolderTextBinding

/**
 *
 * 描述：
 *
 * 创建人：jiale.wei
 * 创建时间：2021/12/1 2:17 下午
 *
 */
object AppHolder {
    fun simpleText(
        holder: RecyclerViewHolder<Pair<String, (View) -> Unit>, HolderTextBinding>,
        pair: Pair<String, (View) -> Unit>
    ) {
        holder.mBinding.root.setViewRadius(8f.dp)
        holder.mBinding.root.text = pair.first
        holder.mBinding.root.onClick { view ->
            pair.second.invoke(view)
        }
    }

    fun simpleText1(
        holder: RecyclerViewHolder<Pair<String, (View) -> Unit>, ViewBinding>,
        pair: Pair<String, (View) -> Unit>
    ) {
        val view = holder.itemView as TextView
        view.setViewRadius(8f.dp)
        view.text = pair.first
        view.onClick { _ ->
            pair.second.invoke(view)
        }
    }
}

class TextHolder : RecyclerViewHolder<Pair<String, (View) -> Unit>, HolderTextBinding> {
    constructor(binding: HolderTextBinding) : super(binding)
    constructor(itemView: View) : super(itemView)

    override fun bindData(data: Pair<String, (View) -> Unit>) {
        AppHolder.simpleText(this, data)
    }
}